#！/bin/bash
source /etc/profile
if [ -n "$1" ]
then
  do_date=$1
else
  do_date=`date -d "-1 day" +%F`
fi
sql="
drop table if exists tmp.shops_tmp;
create table if not exists tmp.tmp_shops as
   select shopid, userid, areaid, shopname,
          shoplevel, status, createtime, 
          modifytime, startdate, enddate
        from dim.dim_trade_shops
        where enddate < '$do_date'
    union all
    select shopid, userid, areaid, shopname,
           shoplevel, status, createtime,
           modifytime, startdate, '9999-12-31' as enddate
         from dim.dim_trade_shops
         where startdate <= '$do_date' and enddate >= '$do_date';
insert overwrite table dim.dim_trade_shops select * from tmp.tmp_shops;"
hive -e "$sql"